package com.zzj.utils;

import com.baomidou.mybatisplus.generator.FastAutoGenerator;
import com.baomidou.mybatisplus.generator.engine.FreemarkerTemplateEngine;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

@Service
public  class CodeGeneratorService {
    @Value("${spring.datasource.url}")
    private String url;
    @Value("${spring.datasource.username}")
    private String username;
    @Value("${spring.datasource.password}")
    private String password;

    public void codeGenerator() {
        FastAutoGenerator.create(url, username, password)
                .globalConfig(builder -> {
                    builder.author("zzj")
                            .enableSwagger()   //开启swagger模式
                            .commentDate("yyyy-MM-dd")
                            .outputDir("Z:\\刺心人文档\\项目\\mingli-convenience-store-API\\mingli-mail\\src\\main\\java");  //制定输出目录
                })
                .packageConfig(builder -> {
                    builder.parent("com.zzj");
                })
                .strategyConfig(builder -> {
                    builder
                            .addTablePrefix("mingli_")
                            .addInclude("mingli_product");
                })
                .templateEngine(new FreemarkerTemplateEngine())
                .execute();
    }
}
